package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.entity.VO.SocialSecurityAreaBasicEntityVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.SocialSecurityAreaBasicEntity;
import io.renren.service.SocialSecurityAreaBasicService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;


/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-06-24 00:22:25
 */
@RestController
@RequestMapping("socialsecurityareabasic")
public class SocialSecurityAreaBasicController {
	@Autowired
	private SocialSecurityAreaBasicService socialSecurityAreaBasicService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("socialsecurityareabasic:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SocialSecurityAreaBasicEntityVO> socialSecurityAreaBasicList = socialSecurityAreaBasicService.queryList(query);
		int total = socialSecurityAreaBasicService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(socialSecurityAreaBasicList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("socialsecurityareabasic:info")
	public R info(@PathVariable("id") Integer id){
		SocialSecurityAreaBasicEntity socialSecurityAreaBasic = socialSecurityAreaBasicService.queryObject(id);
		
		return R.ok().put("socialSecurityAreaBasic", socialSecurityAreaBasic);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("socialsecurityareabasic:save")
	public R save(@RequestBody SocialSecurityAreaBasicEntity socialSecurityAreaBasic){
		String res = socialSecurityAreaBasicService.save(socialSecurityAreaBasic);
		if(res==null)
			return R.ok();
		else
			return R.ok().put("code","1").put("msg",res);
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("socialsecurityareabasic:update")
	public R update(@RequestBody SocialSecurityAreaBasicEntity socialSecurityAreaBasic){
		socialSecurityAreaBasicService.update(socialSecurityAreaBasic);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("socialsecurityareabasic:delete")
	public R delete(@RequestBody Integer[] ids){
		socialSecurityAreaBasicService.deleteBatch(ids);
		
		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/getListinfo/{pid}")
	@RequiresPermissions("socialsecurityareabasic:list")
	public R getListinfo(@PathVariable("pid") Integer pid){
		Map<String, Object> map = new HashMap<>();
		map.put("pid",pid);
		List<Map<String, Object>> res = socialSecurityAreaBasicService.getListinfo(map);

		return R.ok().put("map", res);
	}

	@RequestMapping("/getSysArea")
	@RequiresPermissions("socialsecurityareabasic:list")
	public R getSysArea(){
		Map<String, Object> map = new HashMap<>();
		List<Map<String, Object>> res = socialSecurityAreaBasicService.getListinfo(map);

		return R.ok().put("map", res);
	}
	
}
